package com.atguigu.lease.admin.controller.agreement;

import com.atguigu.lease.admin.service.LeaseAgreementService;
import com.atguigu.lease.model.bean.LeaseAgreement;
import com.atguigu.lease.model.dto.AgreementQueryDto;
import com.atguigu.lease.model.result.Response;
import com.atguigu.lease.model.vo.AgreementItemVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "租约管理模块")
@RestController
@RequestMapping("/admin/agreement")
public class AgreementController {
    @Autowired
    LeaseAgreementService leaseAgreementService;

    @Operation(summary = "3、根据id查询租约详情")
    @GetMapping
    public Response<AgreementItemVo> getById(@RequestParam("id")Long id){
        AgreementItemVo vo = leaseAgreementService.getAgreementItemVoById(id);
        return Response.ok(vo);
    }

    @Operation(summary = "2、新增或更新租约")
    @PostMapping("saveOrUpdate")
    public Response saveOrUpdate(@RequestBody LeaseAgreement leaseAgreement) {
//        leaseAgreementService.saveOrUpdate(leaseAgreement);
        //新增或更新租约：需要校验 房间是否存在 有效的租约
        leaseAgreementService.saveOrUpdateLeaseAgreement(leaseAgreement);

        return Response.ok(null);
    }
    @Operation(summary = "1、条件查询租约分页列表")
    @GetMapping("/page")
    public Response<Page<AgreementItemVo>> page(AgreementQueryDto queryDto){
        return Response.ok(leaseAgreementService.getPage(queryDto));
    }
}
